<template>
<div class="base-container">
  <t-form ref="form" :data="queryParams" label-width="64" @submit="()=>{this.pagination.current=1;this.getList()}"
          @reset="()=>{this.pagination.current=1;this.getList()}">
    <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
      <t-col :span="11" class="query-form-inline">
        <t-form-item label="系统名称" name="name">
          <t-input
            v-model="queryParams.name"
            clearable
            placeholder="请输入系统名称"
            style="width: 240px"
          />
        </t-form-item>
        <t-form-item label="系统状态" name="systemState">
          <t-select style="width: 240px" placeholder="状态" :options="dict.type.system_status"
                    v-model="queryParams.systemState"></t-select>
        </t-form-item>
      </t-col>
      <t-col :span="1" class="operation-container">
        <t-button theme="primary" type="submit">查询</t-button>
        <t-button theme="default" variant="outline" type="reset">重置</t-button>
      </t-col>
    </t-row>
  </t-form>
  <div class="btn-group-inline">
    <t-button @click="dialog.header='新增监管系统';dialog.objId=0;dialog.open = true;" variant="outline" theme="primary">
      <t-icon name="add" slot="icon"/>
      新增
    </t-button>
  </div>
  <t-table
    rowKey="id"
    :data="data"
    :columns="columns"
    hover
    :pagination="pagination"
    :loading="dataLoading"
  >
    <template #systemStatus="{row}">
      {{ row.systemStatus | filterByDict(dict.type.system_status) }}
    </template>
    <template #hostDepts="{row}">
      <div v-for="(item,index) in row.hostDepts" :key="index">{{ item.deptName }}</div>
    </template>
    <template #dutyDepts="{row}">
      <div v-for="(item,index) in row.dutyDepts" :key="index">{{ item.deptName }}</div>
    </template>
    <template #constructionDepts="{row}">
      <div v-for="(item,index) in row.constructionDepts" :key="index">{{ item.deptName }}</div>
    </template>
    <template #aboutMembers="{row}">
      <div v-for="(item,index) in row.aboutMembers.filter(val => val.memberType === '1')" :key="index">{{ item.name }}</div>
    </template>
    <template #aboutMembers2="{row}">
      <div v-for="(item,index) in row.aboutMembers.filter(val => val.memberType !== '1')" :key="index">{{item.memberType | filterByDict(dict.type.yxjk_member_type)}}：{{ item.name }}</div>
    </template>
    <template #op="{ row }">
      <t-button @click="dialog.header='修改监管系统';dialog.objId=row.id;dialog.open = true;" size="small"
                variant="text" class="t-button-link">
        <t-icon name="edit-1" slot="icon"/>
        修改
      </t-button>
      <t-button theme="danger" @click="delObj(row)" size="small" variant="text" class="t-button-link">
        <t-icon name="delete" slot="icon"/>
        删除
      </t-button>
      <t-button @click="toAnalysisPage(row)"  size="small" variant="text" class="t-button-link">
        <t-icon name="chart" slot="icon"/>
        系统分析
      </t-button>
      <t-button @click="toEvaluation(row)"  size="small" variant="text" class="t-button-link">
        <t-icon name="chat-poll" slot="icon"/>
        系统评价
      </t-button>
    </template>
  </t-table>
  <add-edit-system @reload="getList()" :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open" v-if="dialog.open"></add-edit-system>

</div>
</template>

<script>
import addEditSystem from "./components/add-edit-system.vue";

export default {
  name: "system-index",
  dicts: ["system_status", "yxjk_member_type"],
  components:{
    addEditSystem
  },
  data(){
    return {
      dialog:{
        header: '',
        objId: null,
        open: false
      },
      data: [],
      columns: [
        {
          colKey: "name",
          title: "系统名称",
          align: "center",
        },
        {
          colKey: "hostDepts",
          title: "应用主办处室",
          align: "center",
        },
        {
          colKey: "dutyDepts",
          title: "应用责任单位",
          align: "center",
        },
        {
          colKey: "aboutMembers",
          title: "应用联系人",
          align: "center",
        },
        {
          colKey: "constructionDepts",
          title: "建设责任单位",
          align: "center",
        },
        {
          colKey: "aboutMembers2",
          title: "建设责任人/联络员",
          align: "center",
        },
        {
          colKey: "liaisonDate",
          title: "建设年月",
          align: "center",
          width: 100
        },
        {
          colKey: "completeDate",
          title: "完成时间",
          align: "center",
          width: 100
        },
        {
          colKey: "systemStatus",
          title: "系统状态",
          align: "center",
          width: 100
        },
        {
          colKey: "createTime",
          title: "创建时间",
          align: "center",
          width: 180
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 100
        },
      ],
      dataLoading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: '',
        systemState: '',
      },
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10,20,30],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  created(){
    this.getList();
  },
  methods:{
    getList(){
      this.dataLoading = true;
      this.$api.yxjk.system.list(this.queryParams).then(response => {
        this.pagination.total = response.total;
        this.data = response.rows;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
    toAnalysisPage(row){
      this.$router.push({path:`/yxjk/other/system/system-analysis/${row.userName}`,query:{title:`${row.name}-系统分析`}});
    },
    // 系统评价
    toEvaluation(row){
      this.$router.push({path:`/yxjk/other/system/system-applyEvaluation/${row.userName}`,query:{title:`${row.name}-填写评价`}})
    },
    delObj(row){
      const confirmDia = this.$dialog.confirm({
        header: "系统提示",
        body: `是否确认删除系统名称为"${row.name}"的数据项？`,
        theme: "warning",
        onConfirm: ({ e }) => {
          this.$api.yxjk.system.del(row.id).then(
            (res) => {
              this.getList();
              this.$message.success("删除成功");
              // 请求成功后，销毁弹框
              confirmDia.destroy();
            }
          ).catch((e) => {
            this.$message.error(e.toString());
          });
        }
      });
    },
    
  }
}
</script>

<style scoped>

</style>
